import request from '../utils/request';

// 获取公告列表
export const getAnnouncements = (params = {}) => {
  return request({
    url: '/announcements',
    method: 'GET',
    params
  });
};

// 获取最新公告
export const getLatestAnnouncements = (limit = 6) => {
  return request({
    url: '/announcements/latest',
    method: 'GET',
    params: { limit }
  });
};

// 获取公告详情
export const getAnnouncementDetail = (id) => {
  return request({
    url: `/announcements/${id}`,
    method: 'GET'
  });
};

// 创建公告（管理员）
export const createAnnouncement = (data) => {
  return request({
    url: '/announcements',
    method: 'POST',
    data
  });
};

// 更新公告（管理员）
export const updateAnnouncement = (id, data) => {
  return request({
    url: `/announcements/${id}`,
    method: 'PUT',
    data
  });
};

// 删除公告（管理员）
export const deleteAnnouncement = (id) => {
  return request({
    url: `/announcements/${id}`,
    method: 'DELETE'
  });
};

// 发布公告（管理员）
export const publishAnnouncement = (id) => {
  return request({
    url: `/announcements/${id}/publish`,
    method: 'PUT'
  });
};

// 取消发布公告（管理员）
export const unpublishAnnouncement = (id) => {
  return request({
    url: `/announcements/${id}/unpublish`,
    method: 'PUT'
  });
};
